package com.ovopark.organize.server.service.impl;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ovopark.organize.server.mapper.FranchiseesRegistrationRecycleMapper;
import com.ovopark.organize.server.model.entity.FranchiseesRegistrationRecycle;
import com.ovopark.organize.server.model.vo.FranchiseesRegistrationRecycleVo;
import com.ovopark.organize.server.model.vo.SimpleVo;
import com.ovopark.organize.server.service.FranchiseesRegistrationRecycleService;
import com.ovopark.organize.server.util.CommonUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class FranchiseesRegistrationRecycleServiceImpl extends ServiceImpl<FranchiseesRegistrationRecycleMapper, FranchiseesRegistrationRecycle> implements FranchiseesRegistrationRecycleService {

    Logger logger = LoggerFactory.getLogger(FranchiseesRegistrationRecycleServiceImpl.class);


    @Override
    public void recycleByRegistrationId(FranchiseesRegistrationRecycleVo param, Integer userId) {
        // 把之前的 清除
        String registrationIds = CommonUtil.IntegerToStringSql(param.getRegistrationIds());
        baseMapper.deleteByRegistrationId(registrationIds,userId);

        for (Integer registrationId: param.getRegistrationIds() ){
            FranchiseesRegistrationRecycle recycle = new FranchiseesRegistrationRecycle();
            recycle.setRecycleTime(new Date());
            recycle.setRegistrationId(registrationId);
            recycle.setRecycleUserId(userId);
            recycle.setRecycleReasonId(param.getRecycleReasonId());
            recycleByBean(recycle);
        }



    }

    @Override
    public FranchiseesRegistrationRecycle recycleByBean(FranchiseesRegistrationRecycle param) {
        if(param.getId() !=null){
            baseMapper.updateById(param);
        }else {
            param.setRecycleTime(new Date());
            baseMapper.insert(param);
        }
        return param;
    }

    @Override
    public void recoveryRegistrationById(List<Integer> registrationId, Integer userId) {
        String registrationIds = CommonUtil.IntegerToStringSql(registrationId);
        baseMapper.recoveryRegistrationById(registrationIds,userId);
    }

    @Override
    public List<SimpleVo> getRecycleByGroupId(Integer groupId) {
        return baseMapper.getRecycleByGroupId(groupId);
    }
}
